home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / program / progem.lzh / apndx12.prf < prev    next >
Text File  |  1987-06-23  |  10KB  |  440 lines

  1. .!****************************************************************************
  2. .! 
  3. .! ANTIC PUBLISHING INC., COPYRIGHT 1985.  REPRINTED BY PERMISSION.
  4. .!
  5. .! ** Professional GEM ** by Tim Oren
  6. .!
  7. .! Proff File by ST enthusiasts at
  8. .! Case Western Reserve University
  9. .! Cleveland, Ohio
  10. .! uucp : decvax!cwruecmp!bammi
  11. .! csnet: bammi@case
  12. .! arpa : bammi%case@csnet-relay
  13. .! compuserve: 71515,155
  14. .!
  15. .!****************************************************************************
  16. .!
  17. .!            Begin Appendix XII
  18. .!
  19. .!***************************************************************************
  20. .!
  21. .!
  22. .AP XII Sample Code for Part XVI
  23.                   /*****   GEMCL16.H   *****/
  24.  
  25. #define PROGRESS 0      /* TREE */
  26. #define PLINE 2      /* OBJECT in TREE #0 */
  27. #define PROBOX 3      /* OBJECT in TREE #0 */
  28. #define PROBAR 4      /* OBJECT in TREE #0 */
  29. #define STRINGS 1      /* TREE */
  30. #define P1 1      /* OBJECT in TREE #1 */
  31. #define P2 2      /* OBJECT in TREE #1 */
  32. #define PN 3      /* OBJECT in TREE #1 */
  33. .bp
  34.                  /*****  GEMCL16.C ******/
  35.  /* >>>>>>>>>>>>>>>>>>> Progress box setup and cleanup <<<<<<<<<<<<<<<<<<< */
  36.  
  37. /*------------------------------*/
  38. /*    beg_prog         */
  39. /*------------------------------*/
  40.     VOID
  41. beg_prog(rect)
  42.     GRECT    *rect;
  43.     {
  44.     OBJECT    *tree;
  45.     WORD    xdial, ydial, wdial, hdial;
  46.  
  47.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  48.     form_center(tree, &rect->g_x, &rect->g_y, &rect->g_w, &rect->g_h);
  49.     form_dial(0, 0, 0, 0, 0, rect->g_x, rect->g_y, 
  50.         rect->g_w, rect->g_h);
  51.     objc_draw(tree, ROOT, MAX_DEPTH, rect->g_x, rect->g_y, 
  52.         rect->g_w, rect->g_h);
  53.     }
  54.  
  55. /*------------------------------*/
  56. /*    end_prog         */
  57. /*------------------------------*/
  58.     VOID
  59. end_prog(rect)
  60.     GRECT    *rect;
  61.     {
  62.     form_dial(3, 0, 0, 0, 0, rect->g_x, rect->g_y, rect->g_w, rect->g_h);
  63.     }
  64. .bp
  65. /* >>>>>>>>>>>>>>>>>>>> Text line progress indicator <<<<<<<<<<<<<<<<<<<<<<< */
  66.  
  67. /*------------------------------*/
  68. /*    set_prog         */
  69. /*------------------------------*/
  70.     VOID
  71. set_prog(strno)
  72.     UWORD    strno;
  73.     {
  74.     OBJECT    *tree;
  75.     BYTE    *saddr;
  76.  
  77.     rsrc_gaddr(R_TREE, STRINGS, &tree);
  78.     saddr = (BYTE *) (tree + strno)->ob_spec;
  79.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  80.     set_text(tree, PLINE, saddr);
  81.     disp_obj(tree, PLINE);
  82.     }
  83.  
  84. .bp
  85. /* >>>>>>>>>>>>>>>>>>>> Moving bar progress indicator <<<<<<<<<<<<<<<<<<<<<< */
  86.  
  87. /*------------------------------*/
  88. /*    set_prog         */
  89. /*------------------------------*/
  90.     VOID
  91. set_prog(value, maxc)
  92.     WORD    value, maxc;
  93.     {
  94.     WORD    wnew, wold;
  95.     OBJECT    *tree;
  96.     GRECT    box;
  97.  
  98.     rsrc_gaddr(R_TREE, PROGRESS, &tree);
  99.     wold = (tree + PROBOX)->ob_width - 1;    /* Take border into account */
  100.     wnew = wold + 1;
  101.     if (maxc)
  102.         wnew = max(1, ((LONG) value * (LONG) wnew) / maxc); 
  103.     (tree + PROBAR)->ob_width = wnew;
  104.     if (value)
  105.         {
  106.         objc_xywh(tree, PROBAR, &box);
  107.         box.g_x += wold; box.g_w -= wold;
  108.         objc_draw(tree, ROOT, MAX_DEPTH, box.g_x, box.g_y, 
  109.             box.g_w, box.g_h);
  110.         }
  111.     }    
  112. .bp
  113. /* >>>>>>>>>>>>>>>>>>>> Progress indicator check for abort <<<<<<<<<<<<<<<< */
  114.     
  115. /*------------------------------*/
  116. /*    esc_prog         */
  117. /*------------------------------*/
  118.     WORD
  119. esc_prog()
  120.     {
  121.     WORD    which, kr;
  122.     WORD    mx, my, mb, ks, br;        /* Not used, but needed */
  123.  
  124.     FOREVER 
  125.         {
  126.             which = evnt_multi(MU_KEYBD | MU_TIMER,
  127.             0, 0, 0,
  128.             0, 0, 0, 0, 0,
  129.             0, 0, 0, 0, 0,
  130.             0L, 
  131.             0, 0,        /* Zero timer delay */
  132.             &mx, &my, &mb, &ks, &kr, &br);
  133.  
  134.         if (which & MU_KEYBD)
  135.             {
  136.             if ((kr & 0xff) == 0x1B)    /* ESC?          */
  137.                 return (TRUE);        /* else try again */
  138.             }
  139.         else /* if (which & MU_TIMER) */
  140.             return (FALSE);
  141.         }
  142.  
  143.     return (TRUE);        /* Keeps lint happy */ 
  144.     }
  145.  
  146. .bp
  147.   /* >>>>>>>>>>>>>>>>>>>>>>> Progress subroutines  <<<<<<<<<<<<<<<<<<<<<<< */
  148.  
  149.     VOID
  150. set_text(tree, obj, str)
  151.     OBJECT    *tree;
  152.     BYTE    *str;
  153.     WORD    obj;
  154.     {
  155.     TEDINFO    *obspec;
  156.  
  157.     obspec = (TEDINFO *) (tree + obj)->ob_spec;    /* Get TEDINFO address  */
  158.     obspec->te_ptext = str;            /* Set new text pointer */
  159.     obspec->te_txtlen = strlen(str);    /* Set new length    */
  160.     }
  161.  
  162.     VOID
  163. disp_obj(tree, obj)
  164.     OBJECT    *tree;
  165.     WORD    obj;
  166.     {
  167.     GRECT    box;
  168.  
  169.     objc_xywh(tree, obj, &box);
  170.     objc_draw(tree, ROOT, MAX_DEPTH, box.g_x, box.g_y, 
  171.         box.g_w, box.g_h);
  172.     }
  173.  
  174.     VOID
  175. objc_xywh(tree, obj, p)        /* get x,y,w,h for specified object    */
  176.     OBJECT    *tree;
  177.     WORD    obj;
  178.     GRECT    *p;
  179.     {
  180.     objc_offset(tree, obj, &p->g_x, &p->g_y);
  181.     p->g_w = (tree + obj)->ob_width;
  182.     p->g_h = (tree + obj)->ob_height;
  183.     }
  184. .bp
  185.    /* >>>>>>>>>>>>>>>>>>>>>> Box mover examples <<<<<<<<<<<<<<<<<<<<<<<<<< */
  186. /*------------------------------*/
  187. /*    fourway_box         */
  188. /*------------------------------*/
  189.     VOID
  190. fourway_box(vdi_handle, rubber, limit)
  191.     WORD    vdi_handle;
  192.     GRECT    *rubber, *limit;
  193.     {
  194.     UWORD    ox, oy, mx, my, foo, down;
  195.  
  196.     vswr_mode(vdi_handle, MD_XOR);        /* Set VDI modes for box */
  197.     vsl_color(vdi_handle, BLACK);
  198.     wind_update(BEG_MCTRL);            /* Capture mouse     */
  199.  
  200.     ox = rubber->g_x; oy = rubber->g_y;    /* Save off input corner */
  201.     graf_mkstate(&mx, &my, &foo, &foo);    /* Initialize mouse posn */
  202.     do {
  203.         rubber->g_x = min(ox, mx);    /* Choose UL corner     */
  204.         rubber->g_y = min(oy, my);
  205.         rubber->g_w = max(ox, mx) - rubber->g_x + 1;
  206.         rubber->g_h = max(oy, my) - rubber->g_y + 1;
  207.         rc_intersect(limit, rubber);    /* Lock into limit rect  */
  208.         down = rub_wait(vdi_handle, rubber, &mx, &my);
  209.         } while (down);
  210.  
  211.     wind_update(END_MCTRL);            /* Release mouse to GEM  */
  212.     }
  213. .bp
  214. /*------------------------------*/
  215. /*    hot_dragbox         */
  216. /*------------------------------*/
  217.     WORD
  218. hot_dragbox(vdi_handle, box, limit, tree)
  219.     WORD    vdi_handle;
  220.     GRECT    *box, *limit;
  221.     OBJECT    *tree;
  222.     {
  223.     UWORD    ox, oy, mx, my, foo, down;
  224.     WORD    hover_obj, ret_obj;
  225.  
  226.     vswr_mode(vdi_handle, MD_XOR);        /* Set VDI modes for box */
  227.     vsl_color(vdi_handle, BLACK);
  228.     wind_update(BEG_MCTRL);            /* Capture mouse     */
  229.     graf_mkstate(&mx, &my, &foo, &foo);    /* Initialize mouse posn */
  230.     ox = min(box->g_w, max(0, mx - box->g_x) );
  231.     oy = min(box->g_h, max(0, my - box->g_y) );
  232.     hover_obj = NIL;
  233.  
  234.     do {
  235.         box->g_x = mx - ox;
  236.         box->g_y = my - oy;
  237.         rc_constrain(limit, box);    /* Lock into limit rect  */
  238.  
  239.         down = rub_wait(vdi_handle, box, &mx, &my);
  240.  
  241.         if (!inside(mx, my, limit))
  242.             ret_obj = NIL;
  243.         else
  244.             {
  245.             ret_obj = objc_find(tree, ROOT, NIL, mx, my);
  246.             if (ret_obj != NIL)
  247.             if ( !(SELECTABLE & (tree + ret_obj)->ob_flags) )
  248.                 ret_obj = NIL;
  249.             }
  250.         if (ret_obj != hover_obj)
  251.             {
  252.             if (hover_obj != NIL)
  253.                 objc_toggle(tree, hover_obj);
  254.             hover_obj = ret_obj;
  255.             if (hover_obj != NIL)
  256.                 objc_toggle(tree, hover_obj);
  257.             }
  258.         } while (down);
  259.  
  260.     wind_update(END_MCTRL);            /* Release mouse to GEM  */
  261.     if (hover_obj != NIL)
  262.         objc_toggle(tree, hover_obj);
  263.     return (hover_obj);
  264.     }
  265. .bp
  266. /*------------------------------*/
  267. /*    rub_wait         */
  268. /*------------------------------*/
  269.     WORD
  270. rub_wait(vdi_handle, box, mx, my)
  271.     WORD    vdi_handle;
  272.     GRECT    *box;
  273.     WORD    *mx, *my;
  274.     {
  275.     WORD    which, kr;
  276.     WORD    mb, ks, br;            /* Not used, but needed */
  277.  
  278.     graf_mouse(M_OFF, 0x0L);
  279.     vdi_xbox(vdi_handle, box);        /* Draw waiting box */
  280.     graf_mouse(M_ON, 0x0L);
  281.  
  282.            which = evnt_multi(MU_BUTTON | MU_M1,
  283.         0x01, 0x01, 0x00,        /* Wait for button up */
  284.         TRUE, *mx, *my, 1, 1,        /* or mouse move      */
  285.         0, 0, 0, 0, 0,
  286.         0L, 
  287.         0, 0,
  288.         mx, my, &mb, &ks, &kr, &br);
  289.  
  290.     graf_mouse(M_OFF, 0x0L);
  291.     vdi_xbox(vdi_handle, box);        /* Take down waiting box */
  292.     graf_mouse(M_ON, 0x0L);
  293.  
  294.     return (!(which & MU_BUTTON));        /* TRUE if still dragging */
  295.     }
  296. .bp
  297. /* >>>>>>>>>>>>>>>>>>>>>>>> Box Mover Utilities <<<<<<<<<<<<<<<<<<<<<<<<< */
  298.  
  299.     VOID
  300. objc_toggle(tree, obj)
  301.     OBJECT    *tree;
  302.     WORD    obj;
  303.     {
  304.     WORD    state, newstate;
  305.     GRECT    root, ob_rect;
  306.  
  307.     objc_xywh(tree, ROOT, &root);
  308.     newstate = (tree + obj)->ob_state ^ SELECTED;
  309.     objc_change(tree, obj, 0, root.g_x, root.g_y, 
  310.         root.g_w, root.g_h, newstate, 1);
  311.     }
  312.  
  313.     VOID
  314. vdi_xbox(vdi_handle, pt)
  315.     WORD    vdi_handle;
  316.     GRECT    *pt;
  317.     {
  318.     WORD    pxy[10];
  319.  
  320.     vdi_bxpts(pt, pxy);
  321.     vdi_xline(vdi_handle, 5, pxy);
  322.     }
  323.  
  324. .bp
  325.     VOID
  326. vdi_bxpts(pt, pxy)
  327.     GRECT    *pt;
  328.     WORD    *pxy;
  329.     {
  330.     pxy[0] = pt->g_x;
  331.     pxy[1] = pt->g_y;
  332.     pxy[2] = pt->g_x + pt->g_w - 1;
  333.     pxy[3] = pt->g_y;
  334.     pxy[4] = pt->g_x + pt->g_w - 1;
  335.     pxy[5] = pt->g_y + pt->g_h - 1;
  336.     pxy[6] = pt->g_x;
  337.     pxy[7] = pt->g_y + pt->g_h - 1;
  338.     pxy[8] = pt->g_x;
  339.     pxy[9] = pt->g_y;
  340.     }
  341.  
  342. MLOCAL    WORD    hztltbl[2] = { 0x5555, 0xaaaa };
  343. MLOCAL  WORD    verttbl[4] = { 0x5555, 0xaaaa, 0xaaaa, 0x5555 };
  344.  
  345.     VOID
  346. vdi_xline(vdi_handle, ptscount, ppoints)
  347.     WORD    vdi_handle, ptscount, *ppoints;
  348.     {
  349.     WORD        *